﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Domain.Ranges
{
    /// <summary>
    /// Specifications for the determination if one range overlaps with another range.
    /// </summary>
    [TestClass]
    public class WhenDeterminingIfRangeOverlapsAnotherRange
    {
        /// <summary>
        /// Should return false when there is not a single element that the ranges have in common.
        /// </summary>
        [TestMethod]
        public void ShouldReturnFalseWhenRangesHaveNoOverlap()
        {
            Range<DateTime> dateTimeRange = RangeFactory.GetRangeForDaysFromFirstJanuary2000(10);
            Range<DateTime> notOverlappingDateTimeRange = new Range<DateTime>(dateTimeRange.End.AddDays(1), dateTimeRange.End.AddDays(2));

            Assert.IsFalse(dateTimeRange.Overlaps(notOverlappingDateTimeRange));
        }

        /// <summary>
        /// Should return true when there is atleast one element in the beginning that the ranges have in common.
        /// </summary>
        [TestMethod]
        public void ShouldReturnTrueWhenThereIsOverlapAtTheBeginning()
        {
            Range<DateTime> dateTimeRange = RangeFactory.GetRangeForDaysFromFirstJanuary2000(10);
            Range<DateTime> overlappingDateTimeRangeverlappingDateTimeRange = new Range<DateTime>(dateTimeRange.Begin.AddDays(-10), dateTimeRange.Begin.AddDays(2));

            Assert.IsTrue(dateTimeRange.Overlaps(overlappingDateTimeRangeverlappingDateTimeRange));
        }

        /// <summary>
        /// Should return true when there is atleast one element at the end that the ranges have in common.
        /// </summary>
        [TestMethod]
        public void ShouldReturnTrueWhenThereIsOverlapAtTheEnd()
        {
            Range<DateTime> dateTimeRange = RangeFactory.GetRangeForDaysFromFirstJanuary2000(10);
            Range<DateTime> overlappingDateTimeRangeverlappingDateTimeRange = new Range<DateTime>(dateTimeRange.End.AddDays(-2), dateTimeRange.End.AddDays(2));

            Assert.IsTrue(dateTimeRange.Overlaps(overlappingDateTimeRangeverlappingDateTimeRange));
        }

        /// <summary>
        /// Should return true when the tested range is in the range.
        /// </summary>
        [TestMethod]
        public void ShouldReturnTrueWhenTheWholeRangeIsIncluded()
        {
            Range<DateTime> dateTimeRange = RangeFactory.GetRangeForDaysFromFirstJanuary2000(10);
            Range<DateTime> overlappingDateTimeRangeverlappingDateTimeRange = new Range<DateTime>(dateTimeRange.Begin.AddDays(1), dateTimeRange.End.AddDays(-1));

            Assert.IsTrue(dateTimeRange.Overlaps(overlappingDateTimeRangeverlappingDateTimeRange));
        }
    }
}